package com.peoit.honeycomb.rest;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.peoit.honeycomb.application.InformationApplication;
import com.peoit.honeycomb.domain.Information;
import com.peoit.honeycomb.dto.CommonResultDto;
import com.peoit.honeycomb.dto.InformationDto;
import com.peoit.honeycomb.dto.InformationQueryDto;

@Controller
@RequestMapping("/api/information")
public class InformationResource extends BaseResource {

	@Autowired
	InformationApplication informationApplication;

	/**
	 * 获取资讯信息
	 * 
	 * @param dto
	 * @return
	 */
	@RequestMapping("/findInformations")
	public @ResponseBody CommonResultDto findInformations(InformationQueryDto dto) {
		CommonResultDto result = new CommonResultDto();
		try {
			List<Information> informations = informationApplication.findInformations(dto);
			List<InformationDto> dtos = new ArrayList<InformationDto>();
			for (Information information : informations) {
				dtos.add(InformationDto.toDto(information));
			}
			result.setResult(dtos);
			result.setReason("success");
			result.setResult_code("200");
		} catch (Exception e) {
			e.printStackTrace();
			result.setReason("internal error: " + e.getMessage());
			result.setResult_code("500");
		}
		return result;
	}
}
